package com.ycw.util;

import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MyBatisUtil {
	public static SqlSessionFactory getSqlSessionFactory() {
		String resource = "mybatis-config.xml";//配置文件的名字
		SqlSessionFactory factory = null;
		try {
			InputStream is = Resources.getResourceAsStream(resource);//获取配置文件的输入流
			factory = new SqlSessionFactoryBuilder().build(is);//根据配置文件创建sqlSessionFactory
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return factory;
	}
}
